package com.lan.tian;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * @author lovvyang
 * @date 2020/5/24-18:08
 */
/*
 * @PackageName:com.lan.tian
 * @ClassName:DemoDataSource
 * @Description
 * @author lovvyang
 * @date 2020/5/24/18:08
 **/

public class DemoDataSource {
    public static void main(String[] args) throws Exception {
        Properties pro=new Properties();
        pro.load(DemoDataSource.class.getClassLoader().getResourceAsStream(""));
        pro.setProperty("url","jdbc:mysql://localhost:3306/zuoye");
        pro.setProperty("username","root");
        pro.setProperty("password","123456");
        DataSource dataSource = DruidDataSourceFactory.createDataSource(pro);
        // DruidDataSourceFactory.createDataSource();
        Connection connection = dataSource.getConnection();
        String sql ="select * from teacher where Tno = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,"804");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()){
            for (int i = 1; i <=6 ; i++) {
                String string = resultSet.getString(i);
                System.out.println(string);

            }
        }
        preparedStatement.close();
        connection.close();
    }
}
